(function () {
    var serverData = {};
    var serverTable;
    //查看
    jQuery('.seeBtn').on('click', function () {
  	   var selects=getSelect("#dataTable",1);
  	   if(selects.length>1){
  		   $.springLemonDialog({
  		         content: '只能查看一条记录',// 确认文本
  		         clickButton: function (sender, modal, index) {// 按钮事件处理
  		             $(this).closeDialog(modal);
  		         }
  		   }); 
  	   }
  	   else if(selects.length==0){
  		   $.springLemonDialog({
  		         content: '请选择要查看的记录',// 确认文本
  		         clickButton: function (sender, modal, index) {// 按钮事件处理
  		             $(this).closeDialog(modal);
  		         }
  		   }); 
  	   }else if(selects.length==1){
  		 var customerId=selects[0].id;
  		 window.location = window.rootPath+"/ui/CustomerTotalIndex/see?customerId="+customerId;
  	   }	    
     });
    
    //查询
    jQuery('.search_btn').on('click',function(){
    	clearQueryServerData();
    	getServerDate();
        serverTable.draw();
    });
    
    var getServerDate=function(){
    	if(jQuery("#orderArea").val()){
    		serverData.sSuperiorArea=jQuery("#orderArea").val().toString();
    		sSuperiorArea = jQuery("#orderArea").val().toString();
    		//urlsum += "&sSuperiorArea=" + sSuperiorArea;
    	}
    	if(jQuery("#industryInfo").val()){
    		serverData.business=jQuery("#industryInfo").val().toString();
    		business = jQuery("#industryInfo").val().toString();
    		//urlsum += "&createTimeStartDate=" + sBusiness;
    	}
    	if(jQuery("#startDate").val()){
    		serverData.createTimeStartDate=jQuery("#startDate").val().toString();
    		createTimeStartDate = jQuery("#startDate").val().toString();
    		//urlsum += "&sSuperiorArea=" + Contract;
    	}
    	if(jQuery("#endDate").val()){
    		serverData.createTimeEndDate=jQuery("#endDate").val();
    		createTimeEndDate = jQuery("#endDate").val().toString();
    		//urlsum += "&createTimeEndDate=" + createTimeEndDate;
    	}
    	if(jQuery("#zican").val()){
    		serverData.asset=jQuery("#zican").val().toString();
    		asset = jQuery("#zican").val().toString();
    		//urlsum += "&asset=" + asset;
    	}
    	if(jQuery("#creditLevel").val()){
    		serverData.creditLevel=jQuery("#creditLevel").val().toString();
    		creditLevel = jQuery("#creditLevel").val().toString();
    		//urlsum += "&creditLevel=" + creditLevel;
    	}
    	if(jQuery("#customerName").val()){
    		serverData.customerName=jQuery("#customerName").val();
    		customerName = jQuery("#customerName").val();
    		//urlsum += "&creditLevel=" + creditLevel;
    	}
    }
    
    
    var clearQueryServerData=function(){
    	if(serverData.sSuperiorArea) {
    		serverData.sSuperiorArea=null;
    		sSuperiorArea=null;
    	}
    	if(serverData.business) {
    		serverData.business=null;
    		business=null;
    	}
    	if(serverData.createTimeStartDate) {
    		serverData.createTimeStartDate=null;
    		createTimeStartDate=null;
    	}
    	if(serverData.createTimeEndDate) {
    		serverData.createTimeEndDate=null;
    		createTimeEndDate=null;
    	}
    	if(serverData.asset) {
    		serverData.asset=null;
    		asset=null;
    	}
    	if(serverData.creditLevel) {
    		serverData.creditLevel=null;
    		creditLevel=null;
    	}
    	if(serverData.customerName) {
    		serverData.customerName=null;
    		customerName=null;
    	}
    }
    
  //初始化查询条件
    function initQueryParam(){
    	if($('#endDate').val()== "") 
    	$('#endDate').val(new Date().getFullYear()+"-"+((new Date().getMonth() + 1+"").length == 1 ? ("0"+(new Date().getMonth() + 1)) : new Date().getMonth() + 1) +"-"+new Date().getDate());
    	if($('#startDate').val() == "")
    	$('#startDate').val(new Date().getFullYear()+"-01-01");
    }
    
    //默认加载列表
    jQuery(document).ready(function () {
    	
    	initQueryParam();
    	$("#orderArea").multiselect({
		      header: true,
		      height: 175,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	
    	$("#generateState").multiselect({
		      header: true,
		      height: 250,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	
    	$("#creditLevel").multiselect({
		      header: true,
		      height: 250,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	
    	$("#industryInfo").multiselect({
		      header: true,
		      height: 250,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	$("#zican").multiselect({
		      header: true,
		      height: 250,
		      minWidth: 150,
		      classes: '',
		      checkAllText: '选中全部',
		      uncheckAllText: '取消全选',
		      noneSelectedText: '请勾选',
		      selectedText: '# 选中',
		      selectedList: 5,
		      show: null,
		      hide: null,
		      autoOpen: false,
		      multiple: true,
		      position: {},
		      appendTo: "body",
		      menuWidth:null
		    });
    	
    	
    	
    	/*serverData1.sSuperiorArea =jQuery("#orderArea").val();
    	serverData1.sBusiness = jQuery("#industryInfo").val();
    	serverData1.createTimeStartDate= jQuery("#startDate").val();
    	serverData1.createTimeEndDate= jQuery("#endDate").val();*/
    	//serverData1.asset = jQuery("#zican").val();
    	
    	getServerDate();
    	serverTable = jQuery('#dataTable').DataTable({
    		"serverSide": true,
            "ordering": false,
    		"ajax": {
    			"dataType": "json",
    			"type": "get",
    			"cache": false,
    			"url":window.rootPath+ '/ui/CustomerTotalIndex/Allgetpage',
    			"data": function (d) {
    				return $.extend({}, d, serverData);
    			}
    		},
    	    "columns" : [
				{
					data : null,
                    defaultContent : ""// 排序   1
				},
	    	    /*{
		            data: null,
		            defaultContent: "",
		            render: function (data, type, full, meta) {
		            	var id=data.id
		            	var operate ='<input type="checkbox" class="checkchildContract">';
		            	return operate;
		            }   
	            },*/
	            /*{
				    data : 'customerCode'
				},*/
	            {
					data : 'customerName'
				},
	
				{
					data : 'saleArea.superiorArea'
				},
	            {
					data : 'business'
				},{
					data: 'createTime',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
				},
	            {
					data : 'asset'
				},
	            /*{
					data : 'continuelife'
				},*/
	            {
					data : 'creditLevel'
				}
				],
			    "drawCallback": function (oSettings) {
			        var k = 0;
			        var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
			        for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
			            $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
			            k++;
			        }
			    }	
	    	});
	    	serverTable.on('dblclick','tr',function(event) {
	        	event = event|| window.event;
	        	var target = event.target|| event.scrElement;
	        	var data = serverTable.row(this).data();
	        	var id=data.id;
			   	var url=window.rootPath+"/ui/CustomerTotalIndex/see?customerId="+id;
			   	window.location.href = url;
	        	return;
	        });
	    });
})();





